Quickstart
This guide will get you up and running with OpenCLIP in just a few minutes. You’ll learn how to load a pretrained model and perform zero-shot image classification.Prerequisites
Make sure you have OpenCLIP installed:Basic Usage
Here’s a complete example of loading a model and classifying an image:1
Import libraries
Import OpenCLIP and required dependencies:
2
Load model and preprocessing
Create a model with pretrained weights and get the preprocessing transform:
Models are in training mode by default, which affects BatchNorm and dropout layers. Always call
model.eval() for inference.3
Prepare image and text
Load and preprocess an image, then tokenize text labels:
4
Compute embeddings and similarity
Run inference to get image-text similarity scores:
5
Interpret results
Get the most likely label:
Complete Example
Here’s the full code in one block:Exploring Available Models
OpenCLIP provides 80+ pretrained models. List them all:Each model can have multiple pretrained versions trained on different datasets (OpenAI, LAION-400M, LAION-2B, DataComp) with different training configurations.
Using Different Models
Switch to a different model architecture or pretrained variant:GPU Acceleration
For faster inference, move the model to GPU:Loading Local Checkpoints
You can load models from local files instead of downloading:Loading from Hugging Face
Load models directly from the Hugging Face Hub:The first time you load a model, it will be downloaded and cached. Subsequent loads will use the cached version.
Common Use Cases
Image Search
Find the most similar image from a collection:Zero-Shot Classification
Classify images without training examples:Next Steps
Now that you understand the basics, explore more advanced topics:- Model Zoo: Browse all available pretrained models and their performance
- Fine-tuning: Learn how to fine-tune models on your own datasets
- Training: Train CLIP models from scratch on custom data
- Advanced Usage: Batch processing, custom preprocessing, and optimization techniques
For computing billions of embeddings efficiently, check out clip-retrieval which has OpenCLIP support.
